'''
Created on 10/07/2010

@author: Mar
'''
import unittest
from TripleIndirectionBlock import TripleIndirectionBlock
from DoubleIndirectionBlock import DoubleIndirectionBlock
from SimpleIndirectionBlock import SimpleIndirectionBlock


class TripleIndirectionBlockTest(unittest.TestCase):


    def setUp(self):
        self.tBlock = TripleIndirectionBlock()
        self.dBlock0 = DoubleIndirectionBlock()
        self.dBlock1 = DoubleIndirectionBlock()
        self.dBlock2 = DoubleIndirectionBlock()
        self.dBlock3 = DoubleIndirectionBlock()
        self.dBlock4 = DoubleIndirectionBlock()
        self.dBlock5 = DoubleIndirectionBlock()
        self.sBlock0 = SimpleIndirectionBlock()
        self.sBlock1 = SimpleIndirectionBlock()
        self.sBlock2 = SimpleIndirectionBlock()
        self.sBlock3 = SimpleIndirectionBlock()
        self.sBlock4 = SimpleIndirectionBlock()
        self.sBlock5 = SimpleIndirectionBlock()
        self.tBlock.addDoubleIndirectionBlock(self.dBlock0)
        self.tBlock.addDoubleIndirectionBlock(self.dBlock1)
        self.tBlock.addDoubleIndirectionBlock(self.dBlock2)
        self.tBlock.addDoubleIndirectionBlock(self.dBlock3)
        self.tBlock.addDoubleIndirectionBlock(self.dBlock4)
        self.tBlock.addSimpleIndirectionBlock(self.sBlock0)
        self.tBlock.addSimpleIndirectionBlock(self.sBlock1)
        self.tBlock.addSimpleIndirectionBlock(self.sBlock2)
        self.tBlock.addSimpleIndirectionBlock(self.sBlock3)
        self.tBlock.addSimpleIndirectionBlock(self.sBlock4)
        self.tBlock.addDataPointer(1000, 1)
        self.tBlock.addDataPointer(1001, 2)
        self.tBlock.addDataPointer(1002, 3)
        self.tBlock.addDataPointer(1003, 4)
        self.tBlock.addDataPointer(1004, 5)
        self.tBlock.addDataPointer(1005, 6)
        self.dBlock0.addDataPointer(2000, 7)
        self.dBlock0.addDataPointer(2001, 8)
        self.dBlock0.addDataPointer(2002, 9)
        
        
    def tearDown(self):
        pass


    def testAddSimpleIndirectionBlock(self):
        self.tBlock.addSimpleIndirectionBlock(self.sBlock5)
        self.assertTrue(self.dBlock0.getPointers().__contains__(self.sBlock5))
        
    def testAddDoubleIndirectionBlock(self):
        self.tBlock.addDoubleIndirectionBlock(self.dBlock5)
        self.assertTrue(self.tBlock.getPointers().__contains__(self.dBlock5))
        
    def testAddDataPointer(self):
        self.tBlock.addDataPointer(50000, 50)
        self.assertTrue(self.sBlock0.getDataBlockPointers().__contains__(50000))
        
    def testHasSpace(self):
        self.assertTrue(self.tBlock.hasSpace())
        
    def testHasSpaceToABlock(self):
        self.assertTrue(self.tBlock.hasSpaceToABlock())
        
    def testHasSpaceToASimpleBlock(self):
        self.assertTrue(self.tBlock.hasSpaceToASimpleBlock())
        
    def testRemoveDoubleIndirectionBlock(self):
        self.tBlock.addDoubleIndirectionBlock(self.dBlock5)
        self.tBlock.removeDoubleIndirectionBlock(self.dBlock5)
        self.assertTrue(not(self.tBlock.getPointers().__contains__(self.dBlock5)))
        
    def testRemoveSimpleIndirectionBlock(self):
        self.tBlock.addSimpleIndirectionBlock(self.sBlock5)
        self.tBlock.removeSimpleIndirectionBlock(self.sBlock5)
        self.assertTrue(not(self.dBlock0.getPointers().__contains__(self.sBlock5)))
        
    def testRemoveDataPointer(self):
        self.tBlock.addDataPointer(55555, 9999)
        self.tBlock.removeDataPointer(55555)
        self.assertTrue(not(self.sBlock0.getDataBlockPointers().__contains__(55555)))
    
    def testRemoveDataPointer1(self):
        self.sBlock0.addDataPointer(55555, 9999)
        self.tBlock.removeDataPointer(55555)
        self.assertTrue(not(self.sBlock0.getDataBlockPointers().__contains__(55555)))
        
    def testContains(self):
        self.assertTrue(self.tBlock.contains(1000))
        
    def testContains1 (self):
        self.assertFalse(self.tBlock.contains(123456))
        
    def testContainsAndRemove (self):
        self.tBlock.addDataPointer(9876, 1)
        self.tBlock.removeDataPointer(9876)
        self.assertFalse(self.tBlock.contains(9876))
        
    def testGetBlocks(self):
        self.list = self.tBlock.getBlocks()
        self.assertEqual(self.list[0], 1000)
        self.assertEqual(self.list[1], 1001)
        self.assertEqual(self.list[2], 1002)
        self.assertEqual(self.list[3], 1003)
        self.assertEqual(self.list[4], 1004)
        self.assertEqual(self.list[5], 1005)
        self.assertEqual(self.list[6], 2000)
        self.assertEqual(self.list[7], 2001)
        self.assertEqual(self.list[8], 2002)
        
        


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()
    
    
suite = unittest.TestLoader().loadTestsFromTestCase(TripleIndirectionBlockTest)
unittest.TextTestRunner(verbosity=2).run(suite)